<html>
<head><meta charset="utf-8"><title>suggesting a way to alias unnameable types · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html">suggesting a way to alias unnameable types</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227673577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227673577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shad <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227673577">(Feb 24 2021 at 21:12)</a>:</h4>
<p>I recently had to scrap code that I had written because of unnameable types. What it came down to was that I had to store a filtered iterator within a struct, which would act as a wrapper. Following is a minimal example showing the problem with this approach:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">get_my_iter</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">vec</span><span class="p">.</span><span class="n">into_iter</span><span class="p">().</span><span class="n">filter</span><span class="p">(</span><span class="o">|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">2</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">iter</span>: <span class="o">???</span><span class="p">,</span><span class="w"> </span><span class="c1">// it is impossible to write this type</span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">iter</span>: <span class="nc">get_my_iter</span><span class="p">(</span><span class="n">vec</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Because closures are unnameable, it is impossible to spell out the type of <code>MyIterWrapper::iter</code>, which is unavoidable when declaring structs. There are, thankfully, ways to avoid having to spell out these unnameable type:</p>
<ul>
<li>use <code>impl</code> in return types (<code>get_my_iter</code> in this example does exactly that)</li>
<li>use <code>fn</code> instead of closures (the downside is that we can't capture local variables anymore)</li>
<li>re-implement <code>std::iter::Filter</code> by hard-coding the closure in it</li>
<li>use generics (this works in many cases, but not quite in the example above)</li>
</ul>
<p>In the previous example, we cannot straightforwardly use generics in our code:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">get_my_iter</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">vec</span><span class="p">.</span><span class="n">into_iter</span><span class="p">().</span><span class="n">filter</span><span class="p">(</span><span class="o">|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">2</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">MyIterWrapper</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="kt">usize</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">iter</span>: <span class="nc">T</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="kt">usize</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="n">MyIterWrapper</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// This fails to compile, as Self is MyIterWrapper&lt;T&gt;, not MyIterWrapper&lt;get_my_iter's return type&gt;</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">iter</span>: <span class="nc">get_my_iter</span><span class="p">(</span><span class="n">vec</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// This would work</span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">my_iter_wrapper_new</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">MyIterWrapper</span><span class="o">&lt;</span><span class="k">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="kt">usize</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">iter</span>: <span class="nc">get_my_iter</span><span class="p">(</span><span class="n">vec</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I'd like to introduce a way to name these unnameable types without spelling them, by directly referring to the return type of a function. Let <code>return_type_of!</code> be such a function, that takes as input a function and returns its concrete output type.<br>
I could then rewrite the example as follows:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">get_my_iter</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">vec</span><span class="p">.</span><span class="n">into_iter</span><span class="p">().</span><span class="n">filter</span><span class="p">(</span><span class="o">|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">2</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">iter</span>: <span class="nc">return_type_of</span><span class="o">!</span><span class="p">(</span><span class="n">get_my_iter</span><span class="p">),</span><span class="w"> </span><span class="c1">// We can refer to the return type of `get_my_iter` without spelling it</span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">iter</span>: <span class="nc">get_my_iter</span><span class="p">(</span><span class="n">vec</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Alternatively, this type could be stored in a newtype:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">type</span> <span class="nc">MyIterType</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">return_type_of</span><span class="o">!</span><span class="p">(</span><span class="n">get_my_iter</span><span class="p">);</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">iter</span>: <span class="nc">MyIterType</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// ...</span>
</code></pre></div>
<p>Potential issues with this idea are:</p>
<ul>
<li>this is a rather niche problem, as <code>impl</code> return types have solved most of the issues with unnameable types</li>
<li>this adds a layer of complexity; I don't know if there is anything else that use compile-time introspection already in the language</li>
<li>I don't know how this would work with generics</li>
</ul>
<p>I'd love to hear your thoughts on this, and if this idea turns out to be RFC-worthy, help me work out the details :)</p>



<a name="227674342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227674342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227674342">(Feb 24 2021 at 21:17)</a>:</h4>
<p>I think the current plan for this is type-alias impl trait?</p>



<a name="227674709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227674709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227674709">(Feb 24 2021 at 21:20)</a>:</h4>
<p>Something like this <a href="https://rust-lang.github.io/rfcs/2515-type_alias_impl_trait.html#aliasing-impl-trait-in-function-signatures">https://rust-lang.github.io/rfcs/2515-type_alias_impl_trait.html#aliasing-impl-trait-in-function-signatures</a></p>



<a name="227674883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227674883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227674883">(Feb 24 2021 at 21:21)</a>:</h4>
<p>(Perhaps needing an unused function that returns the same thing as <code>get_my_iter</code> to put it into the type alias, if <code>get_my_iter</code> isn't owned by you)</p>



<a name="227677631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227677631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shad <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227677631">(Feb 24 2021 at 21:39)</a>:</h4>
<p>type-alias impl trait looks to be achieving the same thing, except that whose function/object's type it is is determined by the compiler</p>



<a name="227678113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227678113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227678113">(Feb 24 2021 at 21:43)</a>:</h4>
<p>Can you elaborate on that? How does your example look with type alias impl trait and what parts of it are wrong in your eyes?</p>



<a name="227681921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227681921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shad <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227681921">(Feb 24 2021 at 22:05)</a>:</h4>
<p>My example would look like this using RFC 2515:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(type_alias_impl_trait)]</span><span class="w"></span>

<span class="k">type</span> <span class="nc">MyIterType</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">get_my_iter</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">MyIterType</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">vec</span><span class="p">.</span><span class="n">into_iter</span><span class="p">().</span><span class="n">filter</span><span class="p">(</span><span class="o">|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">2</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">iter</span>: <span class="nc">MyIterType</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">iter</span>: <span class="nc">get_my_iter</span><span class="p">(</span><span class="n">vec</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">wrapper</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MyIterWrapper</span>::<span class="n">new</span><span class="p">(</span><span class="fm">vec!</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">]);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="227740324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227740324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227740324">(Feb 25 2021 at 09:34)</a>:</h4>
<p>ah, and the issue is that you need the <code>get_my_iter</code> function at all? That's just a limitation of the current implementation. It isn't fundamental, but we're also not putting any resources into it before shipping the minimal version (which I'm working on)</p>



<a name="227740424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227740424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227740424">(Feb 25 2021 at 09:35)</a>:</h4>
<p>The issue for this situation is <a href="https://github.com/rust-lang/rust/issues/64445">https://github.com/rust-lang/rust/issues/64445</a></p>



<a name="227742203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227742203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227742203">(Feb 25 2021 at 09:50)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> where is the impl trait repo again? :)</p>



<a name="227748255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227748255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227748255">(Feb 25 2021 at 10:45)</a>:</h4>
<p>I can't find it <span aria-label="frown" class="emoji emoji-1f641" role="img" title="frown">:frown:</span> I thought we had a special org for it, but I can't even find that org. Maybe we deleted the org without first moving all repositories?</p>



<a name="227748263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227748263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227748263">(Feb 25 2021 at 10:45)</a>:</h4>
<p>const-eval and similar have been moved already</p>



<a name="227748981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227748981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227748981">(Feb 25 2021 at 10:52)</a>:</h4>
<p>ahhh found it <a href="https://github.com/rust-rfcs/impl-trait">https://github.com/rust-rfcs/impl-trait</a></p>



<a name="227749001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227749001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227749001">(Feb 25 2021 at 10:53)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> ^^</p>



<a name="227749052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227749052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227749052">(Feb 25 2021 at 10:53)</a>:</h4>
<p>it's a bit dated <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="227787594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227787594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227787594">(Feb 25 2021 at 15:45)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> ah, ok. I'm going to just ... deprecate that I think and move to wg-traits</p>



<a name="227788733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227788733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227788733">(Feb 25 2021 at 15:51)</a>:</h4>
<p>yes</p>



<a name="227827182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227827182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shad <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227827182">(Feb 25 2021 at 19:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types/near/227740324">said</a>:</p>
<blockquote>
<p>ah, and the issue is that you need the <code>get_my_iter</code> function at all? That's just a limitation of the current implementation. It isn't fundamental, but we're also not putting any resources into it before shipping the minimal version (which I'm working on)</p>
</blockquote>
<p>I don't quite know what you mean by that. What I can tell you is that my suggestion does basically the same thing, except that the compiler is directly hinted which function/object the concrete type should resolve to.</p>



<a name="227903906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/suggesting%20a%20way%20to%20alias%20unnameable%20types/near/227903906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/suggesting.20a.20way.20to.20alias.20unnameable.20types.html#227903906">(Feb 26 2021 at 09:43)</a>:</h4>
<p>I would imagine that in the future we may permit</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(type_alias_impl_trait)]</span><span class="w"></span>

<span class="k">type</span> <span class="nc">MyIterType</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">iter</span>: <span class="nc">MyIterType</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">MyIterWrapper</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">iter</span>: <span class="nc">vec</span><span class="p">.</span><span class="n">into_iter</span><span class="p">().</span><span class="n">filter</span><span class="p">(</span><span class="o">|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">2</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">wrapper</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MyIterWrapper</span>::<span class="n">new</span><span class="p">(</span><span class="fm">vec!</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">]);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>so we make the field initialization be a defining use.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>